#这道题是一个比较基础的BFS搜索的题，可以参考之前讲的青蛙跳杯子的培训视频

from collections import deque
def min_cz(n, k):
    a = set()
    q = deque([(n, 0)])
    a.add(n)
    while q:
        cur, step = q.popleft()
        if cur == k:
            return step
        cur1 = cur+1
        if cur1 not in a and 1 <= cur1 <= 10**5:
            q.append((cur1, step + 1))
            a.add(cur1)
        cur2 = cur - 1
        if cur2 not in a and 1 <= cur2 <= 10**5:
            q.append((cur2, step + 1))
            a.add(cur2)
        cur3 = cur * 2
        if cur3 not in a and 1 <= cur3 <= 10**5:
            q.append((cur3, step + 1))
            a.add(cur3)
n, k = map(int, input().split())
print(min_cz(n, k))